package com.rrd.dw.mr.gzip.kafka;

import java.io.IOException;
import java.util.Date;
import java.util.regex.Pattern;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rrd.dw.utils.DateUtil;
import com.rrd.dw.utils.MD5Util;
import com.ucredit.babel.common.model.Job;
import com.ucredit.babel.common.model.third.unionpaynew.UnionPayRiskReportData;
import com.ucredit.babel.common.model.third.unionpaynew.UnionPayRiskReportRecord;

/**
 * 银联智慧风险报告
 * @author liubaoxin
 */
@Deprecated
public class UnionPayRiskReportParse {
	public static final String CRT001 =  "\001";
	public static final Pattern CRT001_PATTERN =  Pattern.compile("\001");
	private String timestamstr="";
	private String job_id ="";
	private String system_id ="";
	private StringBuilder sb = new StringBuilder(500);
	private  Text val = new Text();
	 private Text key_text = new Text("unionpay_risk_report");
	 private JSONObject jsonObj = null;
	 /**
		 *  银联智慧风险报告
		 * @param factoryRecord
		 * @throws InterruptedException 
		 * @throws IOException 
		 */
		public  void parseUnionPayRiskReport(Context context,UnionPayRiskReportRecord unionPayRecord) throws IOException, InterruptedException{
			 
	    	Job job = unionPayRecord.getJob();
	    	UnionPayRiskReportData unionPayData = unionPayRecord.getData();
	    	 
	    	sb.delete(0,sb.length());
	    	//job_id
	    	this.job_id = job.getJobID()==null?"":job.getJobID();
	    	//system_id
	    	this.system_id = job.getSystemID()==null?"":job.getSystemID().toString();
	    	//数据时间 
	    	this.timestamstr=unionPayRecord.getTimestamp()==null?"":DateUtil.formateDateStr(new Date(unionPayRecord.getTimestamp()));
	    	jsonObj = JSON.parseObject(unionPayData.getData());
	    	sb.append( MD5Util.getMd5(this.timestamstr+this.job_id)).append(CRT001);
	    	sb.append(job_id).append(CRT001);
	    	sb.append(system_id).append(CRT001);
	    	sb.append(this.timestamstr).append(CRT001); 
	    	sb.append((jsonObj==null || jsonObj.getString("smartId")==null)?"":jsonObj.getString("smartId")).append(CRT001); 
	    	
	    	sb.append(unionPayData.getName()==null?"":unionPayData.getName()).append(CRT001);
	    	sb.append(unionPayData.getIdCardNo()==null?"":unionPayData.getIdCardNo()).append(CRT001);
	    	sb.append(unionPayData.getMobile()==null?"":unionPayData.getMobile()).append(CRT001);
	    	sb.append(unionPayData.getBankNo()==null?"":unionPayData.getBankNo()).append(CRT001);
	    	sb.append(unionPayData.getAddress()==null?"":unionPayData.getAddress()).append(CRT001); 
	    	sb.append(unionPayData.getData()==null?"":unionPayData.getData()).append(CRT001);
	    	sb.append(job.isFinished()!=null && job.isFinished()?"1":"0").append(CRT001);
	    	//爬取开始时间
	    	sb.append(job.getStartTime()==null?"":DateUtil.formateDateStr(job.getStartTime())).append(CRT001);
	    	//爬取结束时间
	    	sb.append(job.getEndTime()==null?"":DateUtil.formateDateStr(job.getEndTime()));
	    	val.set(sb.toString());
	        context.write(key_text, val);
	    
	    	 
		}
		
}
